#!/usr/bin/perl

use ATNF::MoniCA;
use Astro::Time;
use strict;

# Get the weather information for ATCA for the past few years and determine
# what are good, fair and poor weather conditions for the new sensitivity calculator.

# Get the data.
my $start_mjd = perltime2mjd((0, 0, 0, 1, 0, 110));
print "starting MJD = $start_mjd\n";

my @points = ( "site.environment.weather.Pressure",
	       "site.environment.weather.Temperature",
	       "seemon.environment.seemon.AvgRMSPathNoise",
	       "site.environment.weather.RelHumidity",
	       "site.environment.weather.WetPath" );

my $mon = monconnect("monhost-nar");
if (!$mon) {
    die "unable to open MoniCA host connection";
}

for (my $i = 0; $i <= $#points; $i++) {
    my $fname = ".".$points[$i].".txt";
    print $fname."\n";
    if (!-e $fname) {
	my @point_timevals = monsince($mon, $start_mjd, $points[$i], 10000);
	open(O, ">".$fname);
	for (my $j = 0; $j <= $#point_timevals; $j++) {
	    my $tpt = bat2unixtime($point_timevals[$j]->bat);
	    print O $tpt." ".$point_timevals[$j]->val."\n";
	}
	close(O);
    }
}
